class Solution {
public:
    int minNumberOfFrogs(string croakOfFrogs) {
        string t = "croak";
        int n = t.size();
        vector<int> hash(n);
        //char为字符，int是hash的下标
        unordered_map<char,int> index;

        for(int i = 0;i<n;i++)
        {
            index[t[i]] = i;//将index中对应的每一个蛙叫字符变成下标,列如index[c] = 0;      
            //intdex[r] = 1     
        }

       for(auto ch:croakOfFrogs)
       {
            if(ch == 'c')
            {
                if(hash[n-1]!=0) hash[n-1]--;
                hash[0]++;
            }
            else//其他字符
            {
                int i = index[ch];
                if(hash[i-1]==0) return -1;
                hash[i-1]--;
                hash[i]++;
            }
       }
       for(int i = 0;i<hash.size()-1;i++)
       {
        if(hash[i]!=0)
            return -1;
       }
       return hash[n-1];

    }
};